package com.web.service;



import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.web.model.AllproModel;
import com.web.model.DetailModel;
import com.web.model.PersondetailModel;
import com.web.model.ResponseData;
import com.web.model.ResultModel;
import com.web.params.ProblemParams;
import com.web.params.ViewnumParams;
import com.web.params.newpawParams;


import com.web.dao.InfoMapper;



@Service
public class InfoService {
	@Autowired
	private InfoMapper infoMapper;
	//点赞
	public ResponseData LikeAdd(int userId) {
		infoMapper.LikeAdd(userId);
		ResponseData responseData = new ResponseData();
		responseData.success("互动成功");
		return responseData;
	}
	//修改密码
	public ResponseData change(newpawParams params) {
		String loginusername=params.getUsername();
		String oldpwd =infoMapper.haspwd(loginusername);
		String pwd =params.getPassword();
		ResponseData responseData = new ResponseData();
		if(pwd.equals(oldpwd)) {
			infoMapper.change(params);
			responseData.success("修改成功");
			
		}else {
			responseData.failed("密码不一致");
		}
		return responseData;
	}
	//查询
	public ResponseData Queryresults(String username) {
		List<ResultModel> list = infoMapper.listresult(username);
		ResponseData responseData = new ResponseData();
		responseData.success("查询成功",list);
		return responseData;
	
}	
	//问题详情
	public ResponseData detail(int userId) {
		List<DetailModel> list = infoMapper.getdetail(userId);
		ResponseData responseData = new ResponseData();
		responseData.success("读取成功",list);
		return responseData;
	
}
	//个人信息
	public ResponseData Preson(int userId) {
	PersondetailModel personderModel  = infoMapper.getperson(userId);
	ResponseData responseData = new ResponseData();
		responseData.success("读取成功",personderModel);
		return responseData;
		
}		
	//观看数加一
		public ResponseData watch(ViewnumParams params){
			infoMapper.updateview(params);
		ResponseData responseData = new ResponseData();
			return responseData;
			
	}		
		//提问题
				public ResponseData Pro(ProblemParams params){
					Integer userid = params.getUserid();
					String mailbox = params.getMailbox();
					String theme = params.getTheme();
					String title = params.getTitle();
					infoMapper.insertOne(userid,title,mailbox);
					infoMapper.insertTwo(userid,theme);
					ResponseData responseData = new ResponseData();
						responseData.success("保存成功");
						return responseData;
			}		
				//展示所有问题
				public ResponseData Allpro(){
			List<AllproModel> list = infoMapper.getall();
					ResponseData responseData = new ResponseData();
						responseData.success("读取成功",list);
						return responseData;
			}		
				//展示个人问题
				public ResponseData Perpro(int userId){
			List<AllproModel> list = infoMapper.getper(userId);
					ResponseData responseData = new ResponseData();
						responseData.success("读取成功",list);
						return responseData;
			}		
				//删除问题
				public ResponseData deletePro(int topicId){
			            infoMapper.deleteTop(topicId);
					ResponseData responseData = new ResponseData();
						responseData.success("删除成功");
						return responseData;
			}		
		}

		
	


